/*
 * Filename OrderMapping.java 2022年03月24日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.terminal.mapping;

import com.ehome.core.page.PageInfo;
import com.ehome.poct.base.api.dto.doctor.ClinicDTO;
import com.ehome.poct.core.api.dto.check.BldCheckReportVO;
import com.ehome.poct.core.api.dto.check.TestRecordDetailDTO;
import com.ehome.poct.core.api.dto.order.PrePlaceOrderDTO;
import com.ehome.poct.core.api.dto.order.TestOrderDTO;
import com.ehome.poct.core.api.dto.order.TestOrderItemDTO;
import com.ehome.poct.core.api.dto.report.ProfitDTO;
import com.ehome.poct.core.api.vo.order.AddPreOrderVO;
import com.ehome.poct.core.api.vo.order.OrderVO;
import com.ehome.poct.core.api.vo.order.TestOrderVO;
import com.ehome.poct.core.api.vo.order.TestStripPriceProfitVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author wyc
 * @since 2022/03/24 16:14
 **/
@Mapper(componentModel = "spring")
public interface OrderMapping {
    @Mapping(target = "orderType", constant = "1")
    @Mapping(target = "name", expression = "java(report.getReportName() + \"检测订单\")")
    @Mapping(target = "note", expression = "java(\"此检测订单由单项报告 【\" + report.getReportName() + \"】 组成\")")
    @Mapping(target = "payMoney", source = "totalMoney")
    @Mapping(target = "totalMoney", source = "totalMoney")
    TestOrderDTO to(BldCheckReportVO report, String testOrderNo, BigDecimal totalMoney, Integer sourceType, List<TestOrderItemDTO> items);

    @Mapping(target = "testPoctReportId", source = "report.bloodCheckReportId")
    @Mapping(target = "testPoctReportType", source = "report.reportType")
    @Mapping(target = "stripTypeCode", source = "report.projectCode")
    @Mapping(target = "profitId", source = "profit.testStripPriceProfitSchemeId")
    @Mapping(target = "fee", source = "profit.salePrice")
    TestOrderItemDTO toItem(BldCheckReportVO report, TestStripPriceProfitVO profit, String testOrderNo);

    @Mapping(target = "map", ignore = true)
    @Mapping(target = "agentId", source = "clinic.termAgentId")
    @Mapping(target = "testPeoplePortion", constant = "1")
    @Mapping(target = "testMoney", source = "order.totalMoney")
    @Mapping(target = "orderNo", source = "order.testOrderNo")
    @Mapping(target = "deviceType", constant = "2")
    @Mapping(target = "isPay", source = "isPay")
    TestRecordDetailDTO to(TestOrderDTO order, String sno, ClinicDTO clinic, Long testReportId, Integer stripTypeCode, Boolean isPay, LocalDateTime testTime);

    TestOrderDTO to(TestOrderVO vo);

    @Mapping(target = "orderName", source = "name")
    @Mapping(target = "note", expression = "java(\"检测订单由单项报告 【\" + name + \"】 组成\")")
    PrePlaceOrderDTO to(AddPreOrderVO vo, String name, String orderNo, List<Integer> stripCode, Long profitId, Long agentId);


    PageInfo<OrderVO> to(PageInfo<TestOrderVO> page);

    @Mapping(target = "testPoctReportId", source = "report.bloodCheckReportId")
    @Mapping(target = "testPoctReportType", source = "report.reportType")
    @Mapping(target = "stripTypeCode", source = "report.projectCode")
    @Mapping(target = "profitId", source = "profitDTO.testStripPriceProfitId")
    @Mapping(target = "fee", source = "profitDTO.salePrice")
    @Mapping(target = "orderItemName", source = "profitDTO.testConfStripName")
    @Mapping(target = "testReportTypeCode", source = "profitDTO.reportCode")
    TestOrderItemDTO toItem(BldCheckReportVO report, ProfitDTO profitDTO, String testOrderNo);
}